﻿<template>
    <div class="ad-content">
        <div class="ad-main">
            <div class="ad-console-top">
                <div class="ad-console-top-name">评分规则</div>
                <div class="ad-console-top-body">
                </div>
                <div class="ad-console-top-end">
                </div>
            </div>
            <div class="ad-console-body">
                <div class="ad-console-toolbar" v-if="IsAdmin">
                    <el-button type="primary" size="small" icon="el-icon-refresh el-icon--left" @click="generate()">重置绩效评分</el-button>
                    <!--<el-button type="primary" size="small" icon="el-icon-refresh el-icon--left" @click="updatetest()">测试</el-button>-->
                </div>
                <div class="ad-card">
                    <el-table :data="list" size="mini" border style="width: 100%" @sort-change="handleSortChange" >
                        <!--<el-table-column prop="ClassName" label="积分类型" width="200" align="center"></el-table-column>-->
                        <el-table-column prop="Name" label="任务状态" width="200" align="center"></el-table-column>
                        <el-table-column prop="Value" label="分数" width="150" align="center"></el-table-column>
                        <!--<el-table-column prop="Indate" label="有效期" width="150" align="center"></el-table-column>-->
                        <el-table-column prop="Remark" label="绩效说明" align="left"></el-table-column>
                        <el-table-column label="操作" width="80" align="center" v-if="IsAdmin">
                            <template slot-scope="scope">
                                <el-button type="text" size="mini" @click="openDialog(scope.row.IntegralRuleID)">设置</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>
            <el-dialog title="设置评分规则" class="dlg" v-dialogDrag :visible="showDialog" width="500px" @close="closeDialog()">
                <el-form :model="form" class="rule" status-icon :rules="rules" ref="form" label-width="80px">
                    <el-form-item label-width="0px">
                        <el-col :span="24">
                            <el-form-item label="temp" prop="Value">
                                <span slot="label">分<span style="margin-left:23px;">&nbsp;</span>数</span>
                                <el-input-number v-model="form.Value" :controls="false" :min="0" style="width:380px;"></el-input-number>
                            </el-form-item>
                        </el-col>
                    </el-form-item>
                    <el-form-item label-width="0px">
                        <el-col :span="24">
                            <el-form-item label="评分说明" prop="Remark">
                                <el-input v-model="form.Remark" type="textarea" :rows="7"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-form-item>
                    <el-form-item style="margin-bottom:0px;">
                        <el-button type="primary" size="medium" @click="submit">提交</el-button>
                        <el-button size="medium" @click="closeDialog()">关闭</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                list: [],
                showDialog: false,
                IsAdmin: false,
                ShowIndate: false,
                form: {
                    IntegralRuleID: 0,
                    Value: '',
                    Remark: ''
                },
                rules: {
                    Value: [
                        { required: true, message: '请输入分值', trigger: 'blur' }
                    ]
                }
            }
        },
        mounted() {
            App.Page.init(this);
            this.load();
        },
        methods: {
            load() {
                App.Service.post("/plus/Yqd/IntegralRule/GetList", { p: -1 }).then((res) => {
                    if (res.success) {
                        this.IsAdmin = true;// res.Master.UserType == 50;
                        this.list = res.data;
                        //var cname = "";
                        //var len = 1;
                        //var item = null;
                        //this.list.forEach(function (i) {
                        //    if (i.ClassName == cname) {
                        //        i.ClassName = '';
                        //        len++;
                        //    }
                        //    else {
                        //        if (cname != '') item.len = len;
                        //        cname = i.ClassName;
                        //        item = i;
                        //        len = 1;
                        //    }
                        //});
                        //if (item != null) item.len = len;
                    }
                });
            },
            generate() {
                App.Service.post("/plus/Yqd/IntegralRule/UpdateIntegral", {}).then((res) => {
                    if (res.success) {
                        App.Msg.success('所有部门积分重置成功！');
                    }
                });
            },
            updatetest() {
                App.Service.post("/plus/Yqd/IntegralRule/UpdateTest", {}).then((res) => {
                    if (res.success) {
                        App.Msg.success('预警信息重置！');
                    }
                });
            },
    
            openDialog(rID) {
                App.Service.post("/plus/Yqd/IntegralRule/Get", { ruleID: rID }).then((res) => {
                    if (res.success) {
                   
                        this.showDialog = true;
                       
                        this.form = res.data;
                    }
                });
            },
            closeDialog() {
                this.showDialog = false;
                this.reset();

            },
            submit() {
                this.$refs["form"].validate((valid) => {
                    if (valid) {
                        
                        App.Service.post("/plus/Yqd/IntegralRule/Edit", this.form).then((res) => {
                            if (res.success) {
                                App.Msg.success('评分规则设置成功！');
                                this.reset();
                                this.showDialog = false;
                                this.load();
                            }
                        });
                        return;
                    }
                });
            },
            reset() {
                this.form = {
                    PayrollRuleID: 0,
                    Value: '',
                    Remark: ''
                };
                this.$refs["form"].resetFields();
            }
        }
    };
</script>
